package xdpm.nhom16.GUI;

import java.util.List;

import xdpm.nhom16.R;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class PhanTuAdapter extends BaseAdapter
{
	private Context mContext;
	private List<PhanTu> danhSachPhanTu;

	public PhanTuAdapter(Context context, List<PhanTu> dichVu, Handler handler)
	{
		mContext = context;
		danhSachPhanTu = dichVu;
	}

	public int getCount()
	{
		return danhSachPhanTu.size();
	}

	public Object getItem(int pos)
	{
		return danhSachPhanTu.get(pos);
	}

	public long getItemId(int pos)
	{
		return pos;
	}

	public View getView(int pos, View convertView, ViewGroup parent)
	{
		if (convertView == null)
		{
			LayoutInflater inflater = LayoutInflater.from(mContext);
			convertView = inflater.inflate(R.layout.danh_sach_phan_tu, null);
		}

		// Get Selected Entry
		PhanTu entry = danhSachPhanTu.get(pos);
		
		// Set Icon
		ImageView icon = (ImageView)convertView.findViewById(R.id.ff_icon);
		icon.setImageBitmap(entry.getHinhAnh());
		
		// Set Name
		TextView name = (TextView)convertView.findViewById(R.id.ff_name);
		name.setText(entry.getTenDiaDiem());
		
		// Set Type
		TextView type = (TextView)convertView.findViewById(R.id.ff_type);
		type.setText(entry.getChiTiet());
		
		return convertView;
	}

}